import { Dimensions, PixelRatio, Platform, StatusBar } from 'react-native';

// 标签列表 省略
function publicMethodEllipsis(item) {
  return item ?
    (item.length > 4 ? item.substr(0, 4) + "..." :
      item) : ""
}
// 消息通知 省略
function messageEllipsis(item) {
  return item ?
    (item.length > 15 ? item.substr(0, 15) + "....." :
      item) : ""
}
// 系统消息 省略
function systemEllipsis(item) {
  return item ?
    (item.length > 65 ? item.substr(0, 65) + "....." :
      item) : ""
}
// 手机号 **显示
function phoneEllipsis(item) {
  return item.substr(0, 3) + "****" + item.substr(7)
}
// 社圈推广 省略
function socialEllipsis(item) {
  return item ?
    (item.length > 10 ? item.substr(0, 10) + "....." :
      item) : ""
}
// 社圈页面 省略
function socialcircleEllipsis(item) {
  return item ?
    (item.length > 30 ? item.substr(0, 30) + "....." :
      item) : ""
}

const deviceWidth = Dimensions.get('window').width; //设备的宽度
const deviceHeight = Dimensions.get('window').height; //设备的高度
let fontScale = PixelRatio.getFontScale(); //返回字体大小缩放比例
let pixelRatio = PixelRatio.get(); //当前设备的像素密度
let screenPxW = PixelRatio.getPixelSizeForLayoutSize(deviceWidth);
let screenPxH = PixelRatio.getPixelSizeForLayoutSize(deviceHeight);
const defaultPixel = 2;
//px转换成dp
const w2 = Math.round(750 / defaultPixel);
const h2 = Math.round(1334 / defaultPixel);
const scale = Math.min(deviceHeight / h2, deviceWidth / w2); //获取缩放比例
/**
 * 设置text为sp
 * @param size sp
 * @returns number dp
 */
function setSpText(size) {
  var scaleWidth = deviceWidth / 750;
  var scaleHeight = deviceHeight / 1334;
  var scale = Math.min(scaleWidth, scaleHeight);
  size = Math.round((size * scale) / fontScale + 0.5);
  return size;
}
/**
 *
 * @param size 元素的大小 类型为数值类型
 * @returns number dp
 */
const scaleSize = function (size) {
  if (size == 750) {
    return deviceWidth;
  }
  size = Math.round(size * scale + 0.5) / defaultPixel;
  return size;
};
function scaleSizeW(size) {
  var scaleWidth = (size * screenPxW) / 750;
  size = Math.round(scaleWidth / pixelRatio + 0.5);
  return size;
}

module.exports = {
  publicMethodEllipsis,
  messageEllipsis,
  systemEllipsis,
  phoneEllipsis,
  socialEllipsis,
  socialcircleEllipsis,
  setSpText,
  scaleSize,
  scaleSizeW
}
